$def with (v)

$ get_source_record = render_template("history/sources").get_source_record

$def link(url, label):
    $if url: <a href="$url">$label</a>
    $else: $label

$ v = process_version(v)
$ record_id = v.get('machine_comment')
$if record_id:
    $ record = get_source_record(record_id)
    $if v.revision == 1:
       $ record_type = ''
       $if record.source_name not in ('amazon.com', 'Better World Books'):
            $ record_type = 'item' if record.source_name == 'Internet Archive' else 'MARC'
       $:_('Imported from %(source)s  <a href="%(url)s">%(type)s record</a>.', source=link(record.source_url, record.source_name), url=record.url, type=record_type)
    $else:
        $:_('Found a <a href="%(url)s">matching record</a> from %(source)s.', url=record.url, source=link(record.source_url, record.source_name))
$elif 'history_v2' in ctx.features:
    $ t = get_template('recentchanges/' + v.kind + '/comment') or get_template('recentchanges/default/comment')
    $:t(v, v.thing)
$elif v.comment:
    $v.comment
$else:
    <em>$_("Edited without comment.")</em>
